import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/components/Login'
import Home from '@/components/Home'
import centralManagement from '@/components/sysManagement/centralManagement'
import collegeManagement from '@/components/sysManagement/collegeManagement'
import universityManagement from '@/components/sysManagement/universityManagement'
import userManagement from '@/components/scale/userManagement'
import schoolOperation from '@/components/operation/schoolOperation'
import schoolPromotion from '@/components/operation/schoolPromotion'
import schoolOperationData from '@/components/operation/schoolOperationData'
import allSchool from '@/components/operation/allSchool'
import centerOperation from '@/components/operation/centerOperation'
import collegeOperation from '@/components/operation/collegeOperation'
import personalSettings from '@/components/pInformation/personalSettings'
import scaleManagement from '@/components/scale/scaleManagement'
import article from '@/components/scale/article'
import wenzhang from '@/components/scale/wenzhang'
import role from '@/components/sysManagement/role'
import user from '@/components/sysManagement/user'
import Welcome from '@/components/Welcome'
import task from '@/components/scale/task'
import stuInfo from '@/components/scale/stuInfo'
import stuInfoCheck from '@/components/scale/stuInfoCheck'
import miniInfoCheck from '@/components/scale/miniInfoCheck'
import MiniResult from '@/components/scale/MiniResult'
import stuProvince from '@/components/report/stuProvince'
import collegeDistribution from '@/components/report/collegeDistribution'
import collegeProvince from '@/components/report/collegeProvince'
import evaluationCount from '@/components/report/evaluationCount'
import problemStudents from '@/components/report/problemStudents'
import registerUser from '@/components/report/registerUser'
import seriousStu from '@/components/report/seriousStu'



Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: '请登录',
      component: Login,
      meta:{
        isLogin:false
      }
    },
    // 登录页面
    {
      path: '/login',
      component: Login,
      name: '请登录',
      meta:{
        isLogin:false
      }
    },
    //主界面 iconCls 见 http://fontawesome.dashgame.com/
    //运营数据模块
    {
      path: '/home', redirect: '/welcome',component:Home, name: '运营数据', iconCls: 'fa fa-bar-chart',
      meta:{ isLogin:true, auth: "1"},
      children:[
        { path: '/welcome', component: Welcome, name: 'welcome', hidden:true,meta:{ isLogin:true, auth: "0"} },
        {path: '/home/schoolPromotion', component: schoolPromotion, name: '高校推广分布', meta:{ isLogin:true, auth: "2"}},
        {path: '/home/schoolOperation', component: schoolOperation, name: '运营数据', meta:{ isLogin:true, auth: "3"}},
        {path: '/home/schoolOperationData', component: schoolOperationData, hidden:true,name: '高校运营数据', meta:{ isLogin:true, auth: "0"}},
        {path: '/home/centerOperation', component: centerOperation, hidden:true, name: '中心运营数据', meta:{ isLogin:true, auth: "0"}},
        {path: '/home/collegeOperation', component: collegeOperation, hidden:true,name: '院系运营数据', meta:{ isLogin:true, auth: "0"}},
        {path: '/home/allSchool', component: allSchool, hidden:true, name: '更多高校', meta:{ isLogin:true, auth: "0"}},
      ]
    },
    //数据报表模块
    {
      path: '/home', component:Home, name: '数据报表', iconCls: 'fa fa-tasks',
      meta:{ isLogin:true, auth: "4"},
      children:[
        {path: '/home/stuProvince', component: stuProvince, name: '生源地区分布', meta:{ isLogin:true, auth: "47"}},
        {path: '/home/collegeDistribution', component: collegeDistribution, name: '学院人数分布', meta:{ isLogin:true, auth: "48"}},
        {path: '/home/collegeProvince', component: collegeProvince, name: '生源院系分布', meta:{ isLogin:true, auth: "0"}},
        {path: '/home/evaluationCount', component: evaluationCount, name: '评测数据统计', meta:{ isLogin:true, auth: "49"}},
        {path: '/home/problemStudents', component: problemStudents, name: '问题学生分布', meta:{ isLogin:true, auth: "50"}},
        {path: '/home/registerUser', component: registerUser, name: '注册用户查看', meta:{ isLogin:true, auth: "0"}},
        {path: '/home/seriousStu', component: seriousStu, name: '重度抑郁查看', meta:{ isLogin:true, auth: "0"}}
      ]
    },
    //量表模块
    {
      path: '/home', component:Home, name: '心理健康中心', iconCls: 'fa fa-id-card-o',
      meta:{ isLogin:true, auth: "25"},
      children:[
        {path: '/home/scaleManagement', component: scaleManagement, name: '量表管理', meta:{ isLogin:true, auth: "26"}},
        {path: '/home/userManagement', component: userManagement, name: '学生管理', meta:{ isLogin:true, auth: "20"}},
        {path: '/home/stuInfo', component: stuInfo, name: '学生信息', meta:{ isLogin:true, auth: "44"}},
        {path: '/home/stuInfoCheck', component: stuInfoCheck, name: '学生信息查看', meta:{ isLogin:true, auth: "0"}},
        {path: '/home/MiniResult', component: MiniResult, name: 'Mini结果', meta:{ isLogin:true, auth: "45"}},
        {path: '/home/miniInfoCheck', component: miniInfoCheck, name: 'Mini个人结果', meta:{ isLogin:true, auth: "0"}},
        {path: '/home/task', component: task, name: '任务管理', meta:{ isLogin:true, auth: "43"}},
        {path: '/home/wenzhang', component: wenzhang, name: '文章管理', meta:{ isLogin:true, auth: "46"}},
      ]
    },
    //系统管理
    {
      path: '/home', component:Home, name: '系统管理', iconCls: 'fa fa-id-card-o',
      meta:{ isLogin:true, auth: "29"},
      children:[
        // {path: '/home/article', component: article, name: '公告管理', meta:{ isLogin:true, auth: "30"}},
        {path: '/home/universityManagement', component: universityManagement, name: '学校管理', meta:{ isLogin:true, auth: "5"}},
        {path: '/home/collegeManagement', component: collegeManagement, name: '学院管理', meta:{ isLogin:true, auth: "10"}},
        {path: '/home/centralManagement', component: centralManagement, name: '中心管理', meta:{ isLogin:true, auth: "15"}},
        {path: '/home/role', component: role, name: '角色管理', meta:{ isLogin:true, auth: "35"}},
        {path: '/home/user', component: user, name: '用户管理', meta:{ isLogin:true, auth: "39"}},
      ]
    },
    {
      path: '/home', component:Home, name: '个人设置', iconCls: 'fa fa-user-circle',
      meta:{ isLogin:true},
      hidden:true,
      children:[
        {path: '/home/personalSettings', component: personalSettings, name: '个人设置', meta:{ isLogin:true}},
      ]
    },
  ]
});


//挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to将要访问的路径
  // from 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  // next() 放行 next('/login') 强制跳转

  if (to.path === '/login' ) return next()//本来是登录，放
  // 获取token
  const sessionId = window.sessionStorage.getItem('sessionId')//检查是否有sessionId，没有重新登录
  if (!sessionId)
    return next('/login')
  next()
})


export default router
